﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RDPServer.Tool
{
    public partial class frmDBMgr : Form
    {
        static string m_DBFile = AppDomain.CurrentDomain.BaseDirectory + "dsDB.xml";        

        public frmDBMgr()
        {
            InitializeComponent();
            
            LoadData();
        }

        void LoadData()
        {
            this.dsDB.Clear();
            if (System.IO.File.Exists(m_DBFile))
            {
                this.dsDB.ReadXml(m_DBFile);
                foreach (DataRow dr in this.dsDB.dtDB.Rows)
                {
                    dr["DBPwd"] = RDPCommon.Util.DesDecrypt(dr["DBPwd"].ToString());
                }
                this.dsDB.AcceptChanges();
            }
        }

        private void SavetoolStripButton1_Click(object sender, EventArgs e)
        {
            this.dataGridView1.EndEdit();
            if (this.dsDB.HasChanges())
            {
                foreach (DataRow dr in this.dsDB.dtDB.Rows)
                {
                    if (dr.RowState != DataRowState.Deleted)
                    {
                        dr["DBPwd"] = RDPCommon.Util.DesEncrypt(dr["DBPwd"].ToString());
                    }
                }
                this.dsDB.AcceptChanges();
                this.dsDB.WriteXml(m_DBFile);
                LoadData(); //重读
            }
        }

        private void CanceltoolStripButton2_Click(object sender, EventArgs e)
        {
            this.dsDB.RejectChanges();
        }
    }
}
